package com.zmn.oms.dubbo.impl.zmn.third.tmall;

import com.zmn.common.dto2.ResponseDTO;
import com.zmn.oms.common.exception.OmsBaseException;
import com.zmn.oms.dubbo.interfaces.zmn.third.tmall.TmallRemoteService;
import com.zmn.oms.dubbo.utils.DubboConsts;
import com.zmn.oms.third.tmall.service.TmallService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * 天猫勤鸽保外渠道的H5页面接口实现，用来验证核销码等
 *
 * @author xiewenbing
 * @date:2021/07/15 11:30 上午
 */
@Slf4j
@Api(value = "天猫勤鸽保外H5接口", tags = {"天猫勤鸽保外H5接口"})
@Service(loadbalance = "roundrobin", timeout = 5000, version = DubboConsts.INTERFACE_VERSION, validation = "false")
public class TmallRemoteServiceImpl implements TmallRemoteService {

    @Autowired
    private TmallService tmallService;

    /**
     * 天猫勤鸽保外渠道验证核销码
     * @param orderId
     * @param code
     * @return
     */
    @Override
    @ApiOperation(value = "验证核销码", response = ResponseDTO.class)
    public ResponseDTO validateVerificationCode(@ApiParam(value = "订单id") @NotNull(message = "订单ID不能为Null") Long orderId,
                                                @ApiParam(value = "核销码") @NotBlank(message = "核销码不能为空") String code) {

        try {
            tmallService.validateVerificationCode(orderId,code);
        } catch (OmsBaseException exception) {
            return ResponseDTO.fail(exception.getMessage());
        }

        return ResponseDTO.success();
    }

    /**
     * 天猫勤鸽保外渠道读取核销码
     * @param orderId
     * @return
     */
    @Override
    @ApiOperation(value = "读取核销码", response = ResponseDTO.class)
    public ResponseDTO<String> getVerificationCode(@ApiParam(value = "订单id") @NotNull(message = "订单ID不能为Null") Long orderId) {

        try {
            String vCode = tmallService.getVerificationCode(orderId);
            return ResponseDTO.success(vCode);

        } catch (OmsBaseException exception) {
            return ResponseDTO.fail(exception.getMessage());
        }
    }
}
